<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<title>添加编辑配置</title>
		<meta name="keywords" content="raorao Config" />
		<meta name="description" content="[raorao Config]基于Spring Boot Starter的小型Config框架" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />

		<!-- basic styles -->
		<link href="ace/assets/css/bootstrap.min.css" rel="stylesheet" />
	</head>

	<body>
		<form action="#" id="form_project">
			<table>
				<tbody>
				<tr>
					<td><label>key：</label></td>
					<td><input type="text" id="input_key" name="name" placeholder="key" /></td>
				</tr>
				<tr>
					<td><label>val：</label></td>
					<td><input type="text" id="input_val" name="val" placeholder="val" /></td>
				</tr>
				<tr>
					<td><input type="button" id="btn_submit" value="提交" /></td>
					<td><input type="button" id="btn_cancle" value="取消"  /></td>
				</tr>
				</tbody>
			</table>
		</form>
	</body>
</html>
<script src="ace/assets/js/jquery-2.0.3.min.js"></script>
<script src="ace/assets/js/bootstrap.min.js"></script>
<script src="js/JqeryHelper.js"></script>
<script>
	var data={
		"fileId":"",
		"sort":0,
		"type":"string"
	};
	$(function () {
		var url="config/add";
		var fileId=$(this).getQueryVariable("fileId");
		var configId=$(this).getQueryVariable("configId");
		data["fileId"]=fileId
		if(configId){
			url="config/edit";
			$.getJSON("config/queryById?id="+configId,function(result){
				if(result["code"]==200){
					data["id"]=result["data"]["id"];
					data["name"]=result["data"]["name"];
					data["val"]=result["data"]["val"];
					data["fileId"]=result["data"]["fileId"];
					$("#form_project").setForm(data);
				}
			})
		}

		$("#btn_submit").click(function () {
			var json=$("#form_project").serializeJson();
			data["name"]=json["name"];
			data["val"]=json["val"];
			$.post(url,data,function(result){
				if(result["code"]==200){
					alert("成功！")
				}else{
					alert("失败！")
				}
				// parent.initConfigByFileId(data["fileId"]);
				window.close();   //关闭本窗口
			})

		});

		$("#btn_cancle").click(function () {
			window.close();   //关闭本窗口
		});

	});
</script>